<!DOCTYPE html>
<!--
Copyright (c) 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/tracing/base/color.html">
<script>
'use strict';

tr.b.unittest.testSuite(function() {
  test('fromRGB', function() {
    const c = tr.b.Color.fromString('rgb(1, 2, 3)');
    assert.strictEqual(c.r, 1);
    assert.strictEqual(c.g, 2);
    assert.strictEqual(c.b, 3);
    assert.isUndefined(c.a);
  });

  test('fromRGBA', function() {
    const c = tr.b.Color.fromString('rgba(1, 2, 3, 0.5)');
    assert.strictEqual(c.r, 1);
    assert.strictEqual(c.g, 2);
    assert.strictEqual(c.b, 3);
    assert.strictEqual(c.a, 0.5);
  });

  test('fromHex', function() {
    const c = tr.b.Color.fromString('#010203');
    assert.strictEqual(c.r, 1);
    assert.strictEqual(c.g, 2);
    assert.strictEqual(c.b, 3);
    assert.isUndefined(c.a);
  });

  test('toStringRGB', function() {
    const c = new tr.b.Color(1, 2, 3);
    assert.strictEqual(c.toString(), 'rgb(1,2,3)');
  });

  test('toStringRGBA', function() {
    const c = new tr.b.Color(1, 2, 3, 0.5);
    assert.strictEqual(c.toString(), 'rgba(1,2,3,0.5)');
  });

  test('lerpRGB', function() {
    const a = new tr.b.Color(0, 127, 191);
    const b = new tr.b.Color(255, 255, 255);
    const x = tr.b.Color.lerpRGB(a, b, 0.25);
    assert.strictEqual(x.r, 63);
    assert.strictEqual(x.g, 159);
    assert.strictEqual(x.b, 207);
  });

  test('lerpRGBA', function() {
    const a = new tr.b.Color(0, 127, 191, 0.5);
    const b = new tr.b.Color(255, 255, 255, 1);
    const x = tr.b.Color.lerpRGBA(a, b, 0.25);
    assert.strictEqual(x.r, 63);
    assert.strictEqual(x.g, 159);
    assert.strictEqual(x.b, 207);
    assert.strictEqual(x.a, 0.625);
  });

  test('blendRGBA', function() {
    const red = new tr.b.Color(255, 0, 0, 0.5);
    const white = new tr.b.Color(255, 255, 255, 1);
    const x = red.blendOver(white);
    assert.strictEqual(x.r, 255);
    assert.strictEqual(x.g, 127);
    assert.strictEqual(x.b, 127);
    assert.strictEqual(x.a, 1);
  });

  test('fromHSL', function() {
    const reddish = tr.b.Color.fromHSLExplicit(.994, 0.644, .484, 0.8);
    assert.strictEqual(reddish.r, 202);
    assert.strictEqual(reddish.g, 43);
    assert.strictEqual(reddish.b, 49);
    assert.strictEqual(reddish.a, 0.8);

    const gray = tr.b.Color.fromHSLExplicit(0, 0, .50, 1.0);
    assert.strictEqual(gray.r, 127);
    assert.strictEqual(gray.g, 127);
    assert.strictEqual(gray.b, 127);
    assert.strictEqual(gray.a, 1.0);
  });

  test('toHSL', function() {
    const reddish = new tr.b.Color(203, 44, 49, 0.8).toHSL();
    assert.closeTo(reddish.h, .994, 0.01);
    assert.closeTo(reddish.s, 0.644, 0.01);
    assert.closeTo(reddish.l, 0.484, 0.01);
    assert.strictEqual(reddish.a, 0.8);

    const gray = new tr.b.Color(128, 128, 128, 1.0).toHSL();
    assert.strictEqual(gray.h, 0);
    assert.strictEqual(gray.s, 0);
    assert.closeTo(gray.l, .50, 0.01);
    assert.strictEqual(gray.a, 1.0);
  });
});
</script>
